package com.lc.controller;

import com.lc.entity.User;
import com.netflix.discovery.converters.Auto;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.time.Duration;
import java.util.UUID;

/**
 * Author:LiChuang
 * Date: 2022/8/2 17:59
 */
@Slf4j
@RestController
public class LoginController {

    @Autowired
    private StringRedisTemplate redisTemplate;

    private final static Logger LOG = LoggerFactory.getLogger(LoginController.class);

    /*
    开启网关后：访问接口，不需要端口号，只需要网关号就行
        http://localhost:88/doLogin
    开启动态路由后：访问接口，只需在接口前加上服务名称
        http://localhost:88/login-server/doLogin
     */
    @GetMapping("/doLogin")
    public String doLogin(String id, String name) {
        LOG.info("->>>>>>id:" + id + " name:" + name);
        User u = User.builder().id(1).name("jack").age(14).pwd("pwd").build();
        String token = UUID.randomUUID().toString();
        redisTemplate.opsForValue().set(token, String.valueOf(u), Duration.ofSeconds(7200));
        return token;
    }
}
